#!/usr/bin/env python2.7

import sys
from PyQt4 import QtCore, QtGui, uic
 
class MainWindow(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self)
        self.ui = uic.loadUi("Main.ui")
        self.ui.show()
        alpha = 1

        #Slots einrichten
        self.connect(self.ui.Button_Set_1, QtCore.SIGNAL("clicked()"), self.onSET)
        self.connect(self.ui.CBox_90_1, QtCore.SIGNAL('stateChanged(int)'), self.onCHANGE_BOX)
        self.connect(self.ui.CBox_180_1, QtCore.SIGNAL('stateChanged(int)'), self.onCHANGE_BOX)
        self.connect(self.ui.DoubleBox_V_1, QtCore.SIGNAL('valueChanged(double)'), self.onCHANGE_BOX)
        self.connect(self.ui.DoubleBox_Phi_1, QtCore.SIGNAL('valueChanged(double)'), self.onCHANGE_PHI)
        
    def onSET(self):
        print "Everything is set"

    def onCHANGE_BOX(self):
        tmp = self.ui.CBox_90_1.checkState()*45+self.ui.CBox_180_1.checkState()*90+self.ui.DoubleBox_V_1.value()
            
        if tmp != self.ui.DoubleBox_Phi_1.value() :
            self.ui.DoubleBox_Phi_1.setValue(self.ui.CBox_90_1.checkState()*45
                                             +self.ui.CBox_180_1.checkState()*90
                                             +self.ui.DoubleBox_V_1.value())
            
    def onCHANGE_PHI(self):
        tmp = self.ui.CBox_90_1.checkState()*45+self.ui.CBox_180_1.checkState()*90+self.ui.DoubleBox_V_1.value()
            
        if tmp != self.ui.DoubleBox_Phi_1.value() :
            tmp = self.ui.DoubleBox_Phi_1.value()
            if tmp >= 180 :
                self.ui.CBox_180_1.setCheckState(2)
                tmp -= 180
            else :
                self.ui.CBox_180_1.setCheckState(0)
            if tmp >= 90 :
                self.ui.CBox_90_1.setCheckState(2)
                tmp -= 90
                self.ui.DoubleBox_V_1.setValue(tmp)
            else :
                self.ui.CBox_90_1.setCheckState(0)
                self.ui.DoubleBox_V_1.setValue(tmp)
        
        
            

                
app = QtGui.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
        
